import 'package:flutter/material.dart';
import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:kq_flutter_core_widget/utils/toast_util.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_pad_widgets/resources/kq_pad_theme_colors.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_pad_widgets/utils/kq_pad_form_util.dart';
import 'package:kq_flutter_pad_widgets/widgets/button/kq_pad_shadow_button.dart';
import 'package:kq_flutter_pad_widgets/widgets/button/radioButton/kq_pad_radio_button.dart';
import 'package:kq_flutter_pad_widgets/widgets/chart/base/kq_pad_chart_line_bae_mode.dart';
import 'package:kq_flutter_pad_widgets/widgets/chart/base/kq_pad_chart_model.dart';
import 'package:kq_flutter_pad_widgets/widgets/chart/kq_pda_chart_line.dart';
import 'package:kq_flutter_pad_widgets/widgets/chart/kq_pda_chart_line_model.dart';
import 'package:kq_flutter_pad_widgets/widgets/coordMap/kq_pad_coord_map.dart';
import 'package:kq_flutter_pad_widgets/widgets/coordMap/kq_pad_coord_map_entity.dart';
import 'package:kq_flutter_pad_widgets/widgets/dragView/kq_pad_delete_and_drag_list_view.dart';
import 'package:kq_flutter_pad_widgets/widgets/form/entity/kq_form_entity.dart';
import 'package:kq_flutter_pad_widgets/widgets/form/kq_radio_item_view.dart';
import 'package:kq_flutter_pad_widgets/widgets/gradient/kq_%20gradient_bar_view.dart';
import 'package:kq_flutter_pad_widgets/widgets/pullRefresh/kq_pad_refresh_header.dart';
import 'package:kq_flutter_pad_widgets/widgets/rangInput/kq_pad_rang_input.dart';
import 'package:kq_flutter_pad_widgets/widgets/dialog/kq_pad_dialog_util.dart';
import 'package:kq_flutter_pad_widgets/widgets/steps/kq_pad_horizontal_steps.dart';
import 'package:kq_flutter_pad_widgets/widgets/timeLine/entity/kq_pad_date_line_entity.dart';
import 'package:kq_flutter_pad_widgets/widgets/timeLine/kq_pad_date_line.dart';

///
class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  HomePageState createState() => HomePageState();
}

class HomePageState extends State<HomePage> {
  bool selected = false;
  int selectIndex = 1;

  List<KqPadCoordMapEntity> entitys = [
    KqPadCoordMapEntity(
        typeName: '机筒温度(℃)',
        maxValue: '45.00000000000000000000',
        minValue: '1.00000000000000000000',
        points: [
          "1.0",
          "14.8",
          "18.6",
          "27.4",
          "36.2",
          "45.0",
          "44.9",
          "36.2",
          "27.4",
          "18.6",
          "9.8",
          "1.0",
          "1.0",
          "9.8",
          "18.6",
          "27.4",
          "36.2",
          "44.0",
          "44.0",
          "36.2",
          "27.4",
          "18.6",
          "9.8",
          "1.2",
          "27.4"
        ]),
    KqPadCoordMapEntity(
        typeName: '模具温度(℃)',
        maxValue: '45.00000000000000000000',
        minValue: '1.00000000000000000000',
        points: [
          "1.0",
          "9.8",
          "18.6",
          "27.4",
          "36.2",
          "45.0",
          "36.2",
          "27.4",
          "18.6",
          "9.8",
          "1.0",
          "45.0",
          "36.2",
          "27.4",
          "45.0",
          "1.0",
          "9.8",
          "18.6",
          "9.8",
          "1.0",
          "45.0",
          "36.2",
          "18.6",
          "27.4",
          "9.8"
        ]),
    KqPadCoordMapEntity(
        typeName: '射出速度(mm/s)',
        maxValue: '23.00000000000000000000',
        minValue: '1.00000000000000000000',
        points: [
          "1.0",
          "5.4",
          "9.8",
          "14.2",
          "18.6",
          "23.0",
          "14.2",
          "9.8",
          "5.4",
          "1.0",
          "23.0",
          "18.6",
          "9.8",
          "1.0",
          "5.4",
          "18.6",
          "14.2",
          "18.6",
          "9.8",
          "5.4",
          "1.0",
          "23.0",
          "14.2",
          "23.0",
          "23.0"
        ]),
    KqPadCoordMapEntity(
        typeName: '保压压力(bar)',
        maxValue: '16.00000000000000000000',
        minValue: '1.00000000000000000000',
        points: [
          "1.0",
          "4.0",
          "7.0",
          "10.0",
          "13.0",
          "16.0",
          "7.0",
          "4.0",
          "1.0",
          "16.0",
          "13.0",
          "10.0",
          "16.0",
          "7.0",
          "13.0",
          "4.0",
          "1.0",
          "10.0",
          "13.0",
          "7.0",
          "4.0",
          "1.0",
          "16.0",
          "13.0",
          "7.0"
        ]),
    KqPadCoordMapEntity(
        typeName: '机筒温度(摄氏度)',
        maxValue: '55.00000000000000000000',
        minValue: '4.00000000000000000000',
        points: [
          "4.0",
          "4.0",
          "4.0",
          "4.0",
          "4.0",
          "4.0",
          "14.2",
          "14.2",
          "14.2",
          "14.2",
          "14.2",
          "14.2",
          "24.4",
          "24.4",
          "24.4",
          "24.4",
          "24.4",
          "34.6",
          "44.8",
          "44.8",
          "44.8",
          "44.8",
          "44.8",
          "34.6",
          "55.0"
        ]),
  ];

  Widget lineWidget() {
    KqPdaChartLineModel model = KqPdaChartLineModel(
      xDividerList: [
        KqPdaDividerValue(value: 0.7, dividerColor: KqPadThemeColors.textGreen),
        KqPdaDividerValue(value: 0.4, dividerColor: KqPadThemeColors.textRed)
      ],
      yDividerList: [
        KqPdaDividerValue(
            value: 0.9, dividerColor: KqPadThemeColors.textYellow),
        KqPdaDividerValue(
            value: 0.3, dividerColor: KqPadThemeColors.textLightBlue)
      ],
      baseModel: KqPadChartLineBaseModel(
          lineColors: [KqPadThemeColors.bgBlue],
          rightLineColors: [KqPadThemeColors.textRed]),
      chartModel: KqPadChartModel(
        angle: 45,
        isDivide: true,
        isShowClickValue: true,
        isShowSlideValue: true,
        isShowPoint: true,
        isFixMaxY: false,
        sizeHeight: 400,
        sizeWidth: 500,
        unit: '切换压力',
        rightUnit: '有效黏度(K)',
        xRight: 0,
        leftYAxisList: [20, 40, 80, 100, 120],
        rightYAxisList: [30, 60, 90, 120, 150],
      ),
    );
    model.chartArray = [
      [
        KqPdaChartLineValue(
            xValue: '11111',
            yValue: '20',
            lineWidth: 2.r,
            pointColor: KqPadThemeColors.textYellow,
            lineColor: KqPadThemeColors.textRed,
            isShow: true),
        KqPdaChartLineValue(xValue: '222222', yValue: '60', lineWidth: 2.r),
        KqPdaChartLineValue(
            xValue: '3333',
            yValue: '40',
            lineWidth: 2.r,
            pointColor: KqPadThemeColors.textGreen,
            lineColor: KqPadThemeColors.textYellow,
            isShow: true),
        KqPdaChartLineValue(xValue: '444444', yValue: '90', lineWidth: 2.r),
        KqPdaChartLineValue(
            xValue: '555555',
            yValue: '20',
            lineWidth: 2.r,
            pointColor: KqPadThemeColors.textYellow,
            lineColor: KqPadThemeColors.textRed,
            isShow: true),
        KqPdaChartLineValue(
            xValue: '66666', yValue: '120', lineWidth: 2.r, isShow: true),
        KqPdaChartLineValue(
            xValue: '7777777',
            yValue: '100',
            lineWidth: 2.r,
            pointColor: KqPadThemeColors.textYellow,
            isShow: true),
      ]
    ];
    model.chartRightArray = [
      [
        KqPdaChartLineValue(xValue: '1', yValue: '30'),
        KqPdaChartLineValue(xValue: '2', yValue: '60'),
        KqPdaChartLineValue(xValue: '3', yValue: '40'),
        KqPdaChartLineValue(xValue: '4', yValue: '150'),
        KqPdaChartLineValue(xValue: '5', yValue: '70'),
        KqPdaChartLineValue(xValue: '6', yValue: '120'),
        KqPdaChartLineValue(xValue: '7', yValue: '80'),
      ]
    ];
    return Container(
      width: 500,
      height: 500,
      // color: KqPadThemeColors.text8C,
      // alignment: Alignment.center,
      child: KqPdaChartLine(
        // backGroundColor: KqPadThemeColors.bgBlack05,
        height: 400,
        width: 500,
        chartModel: model,
      ),
    );
  }

  final EasyRefreshController easyRefreshController =
      EasyRefreshController(controlFinishRefresh: true);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: EasyRefresh.builder(
        header: KqPadRefreshHeader(),
        controller: easyRefreshController,
        onRefresh: () {
          Future.delayed(Duration(seconds: 3))
              .then((value) => easyRefreshController.finishRefresh());
        },
        childBuilder: (context, physics) {
          return SingleChildScrollView(
            physics: physics,
            child: Padding(
              padding: EdgeInsets.all(8.r),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  lineWidget(),
                  SizedBox(
                    width: 96.r,
                    child: KqPadShadowButton(
                      centerText: "黏度试验",
                      selected: selected,
                      leftWidget: SizedBox(
                        width: 7.r,
                        height: 7.r,
                        child: const ColoredBox(
                          color: Colors.red,
                        ),
                      ),
                      rightWidget: SizedBox(
                        width: 7.r,
                        height: 7.r,
                        child: const ColoredBox(
                          color: Colors.yellow,
                        ),
                      ),
                      onTap: () {
                        setState(() {
                          selected = !selected;
                        });
                      },
                    ),
                  ),
                  SizedBox(
                    height: 30,
                  ),
                  Row(
                    children: [
                      Align(
                        child: KqInkWell(
                          backgroundColor: KqPadThemeColors.bgBlue,
                          radius: 4.r,
                          horizontalPadding: 8.r,
                          verticalPadding: 4.r,
                          child: Text(
                            '确认对话框',
                            style: TextStyle(
                                fontSize: 8.sp,
                                color: KqPadThemeColors.textWhite),
                          ),
                          onTap: () {
                            KqPadDialog.showConfirmDialog(
                                title: '测试',
                                onConfirm: () {
                                  setState(() {});
                                },
                                msg:
                                    '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测？');
                          },
                        ),
                      ),
                      SizedBox(
                        width: 8.r,
                      ),
                      Align(
                        child: KqInkWell(
                          backgroundColor: KqPadThemeColors.bgBlue,
                          radius: 4.r,
                          horizontalPadding: 8.r,
                          verticalPadding: 4.r,
                          child: Text(
                            '消息对话框',
                            style: TextStyle(
                                fontSize: 8.sp,
                                color: KqPadThemeColors.textWhite),
                          ),
                          onTap: () {
                            KqPadDialog.showMsgDialog(
                                title: '数据不足',
                                msg:
                                    '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测');
                          },
                        ),
                      ),
                      SizedBox(
                        width: 8.r,
                      ),
                      Align(
                        child: KqInkWell(
                          backgroundColor: KqPadThemeColors.bgBlue,
                          radius: 4.r,
                          horizontalPadding: 8.r,
                          verticalPadding: 4.r,
                          child: Text(
                            '操作对话框',
                            style: TextStyle(
                                fontSize: 8.sp,
                                color: KqPadThemeColors.textWhite),
                          ),
                          onTap: () {
                            KqPadDialog.showOptDialog(
                                title: '测试标题',
                                onBtnTap: () {
                                  KqToast.showNormal('111');
                                },
                                child: Column(
                                  children: [
                                    Text(
                                        '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测'),
                                  ],
                                ));
                          },
                        ),
                      ),
                      SizedBox(
                        width: 8.r,
                      ),
                      Align(
                        child: KqInkWell(
                          backgroundColor: KqPadThemeColors.bgBlue,
                          radius: 4.r,
                          horizontalPadding: 8.r,
                          verticalPadding: 4.r,
                          child: Text(
                            '自定义弹窗',
                            style: TextStyle(
                                fontSize: 8.sp,
                                color: KqPadThemeColors.textWhite),
                          ),
                          onTap: () {
                            KqPadDialog.showCustomDialog(
                                title: '标题',
                                // showClose: true,
                                customWidget: SizedBox(
                                  height: 100.r,
                                  child: const Column(
                                    children: [
                                      Text(
                                          '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测'),
                                    ],
                                  ),
                                ));
                          },
                        ),
                      ),
                    ],
                  ),
                  InkWell(
                    child: Container(
                      width: 100,
                      height: 30,
                      color: Colors.black,
                    ),
                    onTap: () {
                      setState(() {
                        selectIndex = selectIndex + 1;
                      });
                      print(selectIndex);
                    },
                  ),
                  SizedBox(
                    height: 30,
                  ),
                  Text('平面坐标图'),
                  KqPadCoordMap(
                    height: 500,
                    entitys: entitys,
                    selectedIndex: selectIndex,
                  ),
                  SizedBox(
                    height: 30,
                  ),
                  Text('范围输入框'),
                  // KqPadRangInput(
                  //   title: '机筒温度',
                  //   onSubmittedForMax: (value) {
                  //     print(value);
                  //   },
                  //   onSubmittedForMin: (value) {
                  //     print(value);
                  //   },
                  // ),
                  // KqPadRangInput(
                  //   title: '注射速度',
                  //   unit: 'mm/s',
                  //   onSubmittedForMax: (value) {
                  //     print(value);
                  //   },
                  //   onSubmittedForMin: (value) {
                  //     print(value);
                  //   },
                  // ),
                  SizedBox(
                    height: 30.r,
                  ),
                  KqPadHorizontalSteps(
                    controller: KqStepsController(
                        currentIndex: 1,
                        steps: [
                          {'title': '试验说明'},
                          {'title': '创建试验'},
                          {'title': '试验数据填写'},
                          {'title': '图表和结论'}
                        ].map((e) {
                          return KqStep(
                            stepContentText: e['title'],
                          );
                        }).toList()),
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  KqPadHorizontalSteps(
                    controller: KqStepsController(
                        currentIndex: 1,
                        steps: [
                          {'title': '试验说明试验说明试验说明试验说明'},
                          {'title': '创建试验创建试验'},
                          {'title': '试验数据填写试验数据填写试验数据填写试验数据填写试验数据填写'},
                          {'title': '图表和结论图表和结论'}
                        ].map((e) {
                          return KqStep(
                            stepContentText: e['title'],
                          );
                        }).toList()),
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  KqPadHorizontalSteps(
                    controller: KqStepsController(
                        currentIndex: 1,
                        steps: [
                          {'title': '00000'},
                          {'title': '1111111111111'},
                          {'title': '22222222222222'},
                          {'title': '444444'},
                          {'title': '555555555'},
                        ].map((e) {
                          return KqStep(
                            stepContentText: e['title'],
                          );
                        }).toList()),
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  // KqPadDateLine(
                  //   physics: const NeverScrollableScrollPhysics(),
                  //   data: [
                  //     KqPadDateLineEntity(title: '步骤一'),
                  //     KqPadDateLineEntity(title: '步骤二'),
                  //     KqPadDateLineEntity(title: '步骤三'),
                  //   ],
                  // ),
                  SizedBox(
                    height: 10.r,
                  ),
                  KqPadRadioButton(
                    radioEntity: [
                      IRadioEntity("title1"),
                      IRadioEntity("title2"),
                      IRadioEntity("title3"),
                    ],
                    onChanged: (index) {
                      return Future(() => true);
                    },
                    defaultIndex: 1,
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  KqPadFormUtil.renderFormWidgetListWithBorder([
                    KqPadFormEntity(
                      itemType: ItemType.radio,
                      title: "参数类型",
                      radioData: [
                        RadioData(item: '重量参数（g）', itemId: '0'),
                        RadioData(item: '尺寸参数（mm）', itemId: '1'),
                      ],
                      onRadioChanged: (entity, radioData) {
                        KqToast.showNormal(radioData.item);
                      },
                    ),
                    KqPadFormEntity(
                      itemType: ItemType.edit,
                      title: "参数名称",
                      hint: "请输入参数名称",
                      unit: 'kg',
                      onMonitor: (entity, value) {
                        KqToast.showNormal(value);
                      },
                    ),
                  ]),
                  SizedBox(
                    height: 100,
                    child: KqPadDeleteAndDragListView(
                      itemBuilder: (index) => Container(
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.zero,
                            border: Border.all(
                              width: 1.r,
                              color: const Color(0xFFe0e0e0),
                            )),
                        child: Row(
                          children: [
                            Container(
                              width: 60.r,
                              height: double.infinity,
                              color: const Color(0xFFF0F0F0),
                              padding: EdgeInsets.only(left: 40.r),
                              alignment: Alignment.centerLeft,
                              child: Text(
                                "参数1",
                                style: TextStyle(
                                  fontSize: 6.r,
                                  color: KqPadThemeColors.text26,
                                ),
                              ),
                            ),
                            Expanded(
                              child: Container(
                                color: const Color(0xFFFFFFFF),
                                height: double.infinity,
                                padding:
                                    EdgeInsets.only(left: 6.r, right: 20.r),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  "产品长度(mm)",
                                  style: TextStyle(
                                    fontSize: 6.r,
                                    color: KqPadThemeColors.text26,
                                  ),
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
                      itemCount: 3,
                      onReorder: (int oldIndex, int newIndex) {
                        KqToast.showNormal("$oldIndex移动到$newIndex");

                        ///处理数据移动
                        setState(() {});
                      },
                      onDeleted: (index) {
                        KqToast.showNormal("删除$index");

                        ///删除数据
                        setState(() {});
                      },
                    ),
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  const KqGradientBar(
                    colors: [
                      Colors.red,
                      Colors.orange,
                      Colors.yellow,
                      Colors.green,
                      Colors.blue,
                    ],
                    data: ['10', '20', '30', '40', '50'],
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
